package com.patrol.logisticsmanage.ui.canteen;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.patrol.logisticsmanage.R;
import com.patrol.logisticsmanage.ui.canteen.bean.FoodBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FoodNumAdapter extends RecyclerView.Adapter<FoodNumAdapter.ViewHolder> {
    Context context;
    List<FoodBean> foodBeans;

    public FoodNumAdapter(Context context, List<FoodBean> foodBeans) {
        this.context = context;
        this.foodBeans = foodBeans;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_food_with_number, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        FoodBean foodBean = foodBeans.get(position);
        holder.tvFoodName.setText(foodBean.getName());
        holder.tvFoodNumber.setText("x "+foodBean.getSelectCount());
        holder.tvFoodPrice.setText("￥"+foodBean.getPrice());
        Glide.with(context)
                .load(foodBean.getPicture()).centerCrop()
                .placeholder(R.drawable.food7)
                .error(R.drawable.food7)
                .into(holder.imgFood);
    }

    @Override
    public int getItemCount() {
        return foodBeans.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.img_food)
        ImageView imgFood;
        @BindView(R.id.tv_food_name)
        TextView tvFoodName;
        @BindView(R.id.tv_food_number)
        TextView tvFoodNumber;
        @BindView(R.id.tv_food_price)
        TextView tvFoodPrice;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
